package com.fly.common.util;

import com.fly.common.model.BaseModel;
import com.fly.common.model.SysUserModel;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

import java.util.Date;

/**
 * @CLASSNAME: ModelUtil
 * @author: Fly
 * 日期: 2020/7/5  17:48
 * 描述:
 **/
public class UserlUtil {

    public static SysUserModel getUserModel(){
        SysUserModel obj = (SysUserModel)SecurityUtils.getSubject().getPrincipal();
        return obj;
    }

    public static void setInsertColumn(Object o){
        BaseModel m = (BaseModel) o;
        m.setCreateTime(new Date());
        m.setCreateUser(getUserModel().getUserName());
    }

    public static void setUpdateColumn(Object o){
        BaseModel m = (BaseModel) o;
        m.setUpdateTime(new Date());
        m.setUpdateUser(getUserModel().getUserName());
    }

    public static String getDefaultPassword(String salt){
        SimpleHash pass = new SimpleHash("MD5",Global.DEFAULTPASSWORD, ByteSource.Util.bytes(salt),1024);
        return  pass.toString();
    }

    public static String updatePass(String password,String salt){
        SimpleHash pass = new SimpleHash("MD5",password, ByteSource.Util.bytes(salt),1024);
        return  pass.toString();
    }
}
